/**
 * 
 */
package com.myBase.core.modules.goldcoinaccountdetail.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.myBase.core.entity.GoldcoinAccountDetail;
import com.myBase.core.facade.service.GoldcoinAccountDetailServiceFacade;
import com.myBase.framework.common.config.Global;
import com.myBase.framework.common.utils.StringUtils;
import com.myBase.framework.common.web.BaseController;

/**
 * 金币账户子表-记录用户某批次金币使用概况Controller
 * @author WuJie
 * @version 2017-05-04
 */
@Controller
@RequestMapping(value = "${adminPath}/goldcoinaccountdetail/goldcoinAccountDetail")
public class GoldcoinAccountDetailController extends BaseController {

    @Autowired
    private GoldcoinAccountDetailServiceFacade goldcoinAccountDetailService;

    @ModelAttribute
    public GoldcoinAccountDetail get(@RequestParam(required = false) String id) {
        GoldcoinAccountDetail entity = null;
        if (StringUtils.isNotBlank(id)) {
            entity = goldcoinAccountDetailService.get(id);
        }
        if (entity == null) {
            entity = new GoldcoinAccountDetail();
        }
        return entity;
    }

    @RequiresPermissions("goldcoinaccountdetail:goldcoinAccountDetail:view")
    @RequestMapping(value = { "list", "" })
    public String list(GoldcoinAccountDetail goldcoinAccountDetail, HttpServletRequest request,
            HttpServletResponse response, Model model) {
        /* Page<GoldcoinAccountDetail> page = goldcoinAccountDetailService
                .findPage(new Page<GoldcoinAccountDetail>(request, response), goldcoinAccountDetail);
        model.addAttribute("page", page);*/
        return "modules/goldcoinaccountdetail/goldcoinAccountDetailList";
    }

    @RequiresPermissions("goldcoinaccountdetail:goldcoinAccountDetail:view")
    @RequestMapping(value = "form")
    public String form(GoldcoinAccountDetail goldcoinAccountDetail, Model model) {
        model.addAttribute("goldcoinAccountDetail", goldcoinAccountDetail);
        return "modules/goldcoinaccountdetail/goldcoinAccountDetailForm";
    }

    @RequiresPermissions("goldcoinaccountdetail:goldcoinAccountDetail:edit")
    @RequestMapping(value = "save")
    public String save(GoldcoinAccountDetail goldcoinAccountDetail, Model model,
            RedirectAttributes redirectAttributes) {
        if (!beanValidator(model, goldcoinAccountDetail)) {
            return form(goldcoinAccountDetail, model);
        }
        goldcoinAccountDetailService.save(goldcoinAccountDetail);
        addMessage(redirectAttributes, "保存金币账户子表成功");
        return "redirect:" + Global.getAdminPath() + "/goldcoinaccountdetail/goldcoinAccountDetail/?repage";
    }

    @RequiresPermissions("goldcoinaccountdetail:goldcoinAccountDetail:edit")
    @RequestMapping(value = "delete")
    public String delete(GoldcoinAccountDetail goldcoinAccountDetail, RedirectAttributes redirectAttributes) {
        goldcoinAccountDetailService.delete(goldcoinAccountDetail);
        addMessage(redirectAttributes, "删除金币账户子表成功");
        return "redirect:" + Global.getAdminPath() + "/goldcoinaccountdetail/goldcoinAccountDetail/?repage";
    }

}